package com.shopping.product.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.shopping.product.vo.SpuSaveVo;
import org.springframework.web.bind.annotation.*;

import com.shopping.product.entity.SpuInfoEntity;
import com.shopping.product.service.SpuInfoService;
import com.shopping.common.utils.PageUtils;
import com.shopping.common.utils.R;

import javax.annotation.Resource;


/**
 * spu信息
 *
 * @author Europa
 * @email qw1124sdo8@live.com
 * @date 2020-04-11 22:49:19
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Resource
    private SpuInfoService spuInfoService;

    @PostMapping("{spuId}/up")
    public R up(@PathVariable("spuId") Long spuId) {

        return R.ok().put("上架", null);
    }

    /**
     * spu检索
     *
     * @param params map{t=时间戳, page=页码, limit=每页内容条数, key=检索关键字}
     * @return 状态码 + 操作信息 + 含SpuInfoEntity的list的PageUtils实体
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = spuInfoService.queryPageByCondition(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id) {
        SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 新增商品
     *
     * @param spuSaveVo SpuSaveVo实体
     * @return 状态码 + 操作信息
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody SpuSaveVo spuSaveVo) {
//		spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuSaveVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:updateSort")
    public R update(@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
